<?php
/* 
 * Amnesia is Copyright (c) 2010 Mark Russell
 * 
 * Contact: info@amnesia-app.com	
 * 
 * This file is part of Amnesia.
 * 
 * Amnesia is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Amnesia is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Amnesia. If not, see <http://www.gnu.org/licenses/>.
 *
 */

session_start();
include("../db/db.php");
include("../login/login.php");
include("../common/version.inc.php");

// Send unlogged-in access attempts straight to the login form
if(!$logged_in)
	header("Location: ../");

// Get the current user from the session

$query = "SELECT `user_id`, `firstname`, `lastname`, `timeout`, `count` FROM `user` WHERE `username`='" . $user_name . "'";

if(!($result = @ mysql_query ($query, $con)))
	showerror();

while($array = mysql_fetch_array($result)) {
	$id = $array['user_id'];
	$firstname = $array['firstname'];
	$lastname = $array['lastname'];
	$timeout = $array['timeout'];
	//$user_count = $array['count'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Amnesia. Feel free to forget.</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" href="../css/amnesia.css" type="text/css" media="screen" />
	<script type="text/javascript" src="../lib/jquery.js"></script>
	<script type="text/javascript" src="prefs.js"></script>
<?
	// Set Javascript global vars from db call
	echo "<script type=\"text/javascript\" language=\"javascript\">";
	echo "var user = \"" . $id . "\";";
	echo "var lock_out_time = \"" . $timeout . "s\";";
	//echo "var user_count = " . $user_count . ";";
	echo "</script>";
?>
</head>
<body>
	<div id="main">
		<div id="container">
			<div id="left_retainer"></div>
			<div id="col1">
				<img src="../img/core/amnesia_logo.jpg" alt="Amnesia. Feel free to forget" width="187" height="184"/>
				<div id="login_status_locked">
					<strong>Amnesia is locked</strong><br/>
					<img src="../img/core/arrow_small.png" alt="arrow_small" width="4" height="7"/> <a class="col1" href="../secure">Enter your keyphrase</a>
				</div>
				<div id="user_status">
					<strong>Signed-in as <? echo $firstname . "&nbsp;" . $lastname ?></strong><br/>
					<img src="../img/core/arrow_small.png" alt="arrow_small" width="4" height="7"/> <a class="col1" href="../login/logout.php">Sign-out</a>
				</div>
			</div>
			
			<!-- Locked single column -->
			<div id="col_container_locked">
				<div id="status_locked">
					<div id="status_left"></div>
					<div id="status_right">
						<div id="amnesia_locked">Amnesia is locked<img class="status_icn" src="../img/core/lock_icon.png" alt="lock_icon" width="9" height="12"/></div>
						<div class="loading" style="display: none;"><span>Loading </span><img class="status_icn" src="../img/core/loading.gif" alt="loading" width="14" height="14"/></div>
					</div>
				</div>
				<div id="login">
					<div id="login_contents_register">
						<p id="key_message">Preferences</p>
						
						<div id="prefs_form">
							<p class="text">Change your basic usage settings for Amnesia</p>
							<p>&nbsp;</p>
							<form action="#">
								<fieldset>
									<input type="hidden" id="user_id" value="<? echo $id ?>"/>
									<label class="prefs_label" for="timeout">How long should Amnesia wait while inactive before automatically locking?</label>
									<select class="prefs_form" id="timeout">
										<option value="600" <? if($timeout == "600")echo 'selected="selected"'; ?>>5 minutes (recommended)</option>
										<option value="1200" <? if($timeout == "1200")echo 'selected="selected"'; ?>>10 minutes</option>
										<option value="3600" <? if($timeout == "3600")echo 'selected="selected"'; ?>>30 minutes</option>
										<option value="7200" <? if($timeout == "7200")echo 'selected="selected"'; ?>>1 hour</option>
										<option value="86400" <? if($timeout == "86400")echo 'selected="selected"'; ?>>12 hours</option>
										<option value="172800" <? if($timeout == "172800")echo 'selected="selected"'; ?>>1 day</option>
										<option value="0" <? if($timeout == "0")echo 'selected="selected"'; ?>>Don't automatically lock (not recommended)</option>
									</select>
								</fieldset>
								<p>&nbsp;</p>
								<div class="rule_top_pad"></div>
								<div class="prefs_buttonset">
									<a id="update_preferences" href="javascript:void(0)"><img src="../img/buttons/update_prefs_link.png" alt="update_prefs_link" width="117" height="22" /></a>
								</div>
							</form>
						</div>
						
						<div id="prefs_done" style="display: none;">
							<p class="text">Your preferences have been updated.</p>
							<div class="rule_top_pad"></div>
							<div class="prefs_buttonset">
								<a href="../secure"><img src="../img/buttons/back_to_link.png" alt="back_to_link" width="117" height="22" /></a>
							</div>
						</div>
						<p class="version">You are running Amnesia version <? echo $version ?></p>
					</div>
				</div>
				
			</div>
		</div>
	</div>
</body>
</html>
